package com.commit.filter;

import com.commit.domain.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author:zyh
 * @Time:2021-02-28-18:07
 * @email:1269231889@qq.com
 */
public class GlobalInterceptor implements HandlerInterceptor {
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        Subject subject = SecurityUtils.getSubject();
        User principal = (User) subject.getPrincipal();
        modelAndView.addObject("user",principal);
        modelAndView.addObject("contextPath",request.getContextPath());
    }
}
